var flag = true;
function checkAll(e){
	var flag=$(e).prop("checked");
	if(init.chooseType=="one"){
		layer.msg("只能选择一件商品，不能多选！");
		return false;
	}
	if(flag){
		$(".goods-checkbox").prop("checked",true);
	}else{
		$(".goods-checkbox").prop("checked",false);
	}
}
function checkOne(e){
	var flag=$(e).prop("checked");
	if(init.chooseType=="one" && flag){
		$(".goods-checkbox").prop("checked",false);
		$(e).prop("checked",true);
	}
}
$(function(){
	$("#search-button").click(function(){
		var keyword=$("input[name='keyword']").val();
		var url=basePath+"/goods/queryGoodsList.shtml?pageNo="+1+"&keyword="+keyword+"&chooseType="+init.chooseType;
		window.location.href=url;
	})
	$("#save-button").click(function(){
		var goodsChecked=$(".goods-checkbox:checked");
		var chooseType=init.chooseType;
		if(goodsChecked.length==0){
			layer.msg("请选择商品！");
			return false;
		}
		var goodsArray=new Array();
		if(chooseType == 'one'){
			var goodsId=$(goodsChecked[0]).val();
			var goodsName=$(goodsChecked[0]).attr("data-name");
			var coverImage=$(goodsChecked[0]).attr("data-image");
			var price=$(goodsChecked[0]).attr("data-price");
			var goods={
					"id":goodsId,
					"name":goodsName,
					"coverImage":coverImage,
					"price":price
			}
			goodsArray.push(goods);
		}else{
			for(i=0;i<goodsChecked.length;i++){
				var goodsId=$(goodsChecked[i]).val();
				var goodsName=$(goodsChecked[i]).attr("data-name");
				var coverImage=$(goodsChecked[i]).attr("data-image");
				var price=$(goodsChecked[i]).attr("data-price");
				var goods={
						"id":goodsId,
						"name":goodsName,
						"coverImage":coverImage,
						"price":price
				}
				goodsArray.push(goods);
			}
		}
		if(flag){
			flag=false;
			parent.closeGoodsLayer(1,goodsArray);
		}
	})
})

function fanye(pageNo){
	var url=basePath+"/goods/queryGoodsList.shtml?pageNo="+pageNo+"&keyword="+init.keyword+"&chooseType="+init.chooseType;
	window.location.href=url;
}